﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.Plumbing
{
	public partial class FormChooseHydrant : System.Windows.Forms.Form
	{
		public string ImageName
		{
			get
			{
				return this.imageName;
			}
			set
			{
				this.imageName = value;
			}
		}

		public FormChooseHydrant(string _imageName, List<ListItem> listInfos)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Location = new System.Drawing.Point(100, 100);
			base.Icon = Resource.YArchitechIcon;
			this.InitListView(_imageName, listInfos);
		}

		public void InitListView(string _imageName, List<ListItem> listInfos)
		{
			if (listInfos.Count > 0)
			{
				this.listView.Clear();
				foreach (ListItem listItem in listInfos)
				{
					Image image = Image.FromFile(listItem.Value);
					this.listView.LargeImageList.Images.Add(listItem.Name, image);
					ListViewItem listViewItem = new ListViewItem();
					listViewItem.Text = listItem.Name;
					listViewItem.Tag = listItem;
					listViewItem.ImageKey = listItem.Name;
					this.listView.Items.Add(listViewItem);
				}
				foreach (object obj in this.listView.Items)
				{
					ListViewItem listViewItem2 = (ListViewItem)obj;
					if (listViewItem2.Text == _imageName)
					{
						listViewItem2.Selected = true;
						break;
					}
				}
			}
		}

		private void btCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void btOk_Click(object sender, EventArgs e)
		{
			if (this.listView.Items.Count > 0)
			{
				foreach (object obj in this.listView.Items)
				{
					ListViewItem listViewItem = (ListViewItem)obj;
					if (listViewItem.Selected)
					{
						this.imageName = listViewItem.Text;
						break;
					}
				}
			}
			base.DialogResult = DialogResult.OK;
		}

		private string imageName = "";
	}
}
